/**
 * Created by oneminute on 7/18/14.
 */

var assert = require("assert");
var should = require("should");
var logger = require("../../lib/utils/logger");
var testutils = require("../testutils");
var lz = require("../../lib/utils/modules")();

describe("测试Account模块。", function () {
    var account01 = null;

    it("正常创建Account对象。", function (done) {
        account01 = new lz.Account({
            id: lz.Utils.getUUID("b_"),
            uid: "u_test0001",
            account: "10880001",
            publisher: "qq"
        });
        account01.save(function (_err, _account) {
            testutils.check(done, function () {
                _account.account.should.equal(account01.account);
            });
        });
    });

    it("根据_id正常加载Account对象。", function (done) {
        var account02 = new lz.Account({_id: account01._id});
        account02.load(function(_err, _account) {
            testutils.check(done, function () {
                account02.account.should.equal(account01.account);
            });
        });
    });

    it("根据AQL正常加载Account对象。", function (done) {
        var account03 = new lz.Account();
        account03.load({method: "byProp", prop: "uid", value: account01.uid}, function(_err, _account) {
            testutils.check(done, function() {
                account03.account.should.equal(account01.account);
            });
        });
    });

    it("根据uid使用list方法正常列出Account对象。", function (done) {
        var account04 = new lz.Account({uid: account01.uid});
        account04.list({method: "byProp", prop: "uid"}, function(_err, _accounts) {
            testutils.check(done, function() {
                assert.equal(_accounts.length > 0, true);
                lz.Logger.info("accounts: ", _accounts);
            });
        });
    });

    it("使用delete方法删除Account对象。", function (done) {
        account01.delete(function(_err) {
            lz.ArangoDB.getObjectById(account01._id, function(_err, _obj) {
                testutils.check(done, function() {
                    assert.equal(_obj, null);
                });
            });
        });
    });

    after(function(done) {
        /*lz.ArangoDB.deleteObjectById(account01._id, function() {
            done();
        });*/
        done();
    });
});
